<%-- 
    Document   : classification
    Created on : Apr 19, 2012, 11:38:01 PM
    Author     : asus
--%>
<%@page import="utility.AttTest"%>
<%@page import="weka.core.Instances"%>
<%@page import="weka.core.Instance"%>
<%@page import="algorithm.*"%>
<%@page import="datastructure.*"%>
<%@page import="java.io.FileOutputStream"%>
<%@page import="java.io.File"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Name       : Office Memo  
Description: A two-column, fixed-width design with dark color scheme.
Version    : 1.0
Released   : 20120401

-->
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>Office Memo by Free CSS Templates</title>
        <link href="http://fonts.googleapis.com/css?family=Arvo" rel="stylesheet" type="text/css" />
        <link href="http://fonts.googleapis.com/css?family=Coda:400,800" rel="stylesheet" type="text/css" />
        <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
    </head>
    <body>
        <%
           String output = "output";
           
           // 1. set variable        
           Instances dataset = (Instances) session.getAttribute("dataset");
           
           DecisionTreeModel dtm = (DecisionTreeModel) session.getAttribute("dtm");
           NaiveBayesianModel nbm = (NaiveBayesianModel) session.getAttribute("nbm");
           KNearestNeighbourModel knnm = (KNearestNeighbourModel) session.getAttribute("knnm");
           
           String algo = request.getParameter("algo");
           String software = request.getParameter("software");
           String input = request.getParameter("input");
           
           String checkedDT = "";
           String checkedNB = "";
           String checkedKNN = "";
           String checkedWEKA = "";
           String checkedWIDI = "";
           
           //2. set value
           if(algo==null){
               algo = (String) session.getAttribute("algo");
           } else {
               session.setAttribute("algo", algo);
           }
           if(software==null){
               software = (String) session.getAttribute("software");
           } else {
               session.setAttribute("software", software);
           }
                  
           if(algo!=null){
               if(algo.equals("dt")){
                   checkedDT = "checked";
               } else if(algo.equals("nb")){
                   checkedNB = "checked";
               } else if(algo.equals("knn")){
                   checkedKNN = "checked";
               }
           }
           if(software!=null){
               if(software.equals("weka")){
                   checkedWEKA = "checked";
               } else if( software.equals("widi")){
                   checkedWIDI = "checked";
               }
           }
           
           //3. get output
           if(dataset!=null){
               if(software!=null){
                    Instance instance; 
                    AttTest at = new AttTest();
                    if(software.equals("weka")){
                        if(input!=null){         
                            if (input.length() != 23) {
                                output = "invalid input";
                            } else {
                                instance = at.getInstance(input);
                                output = "hasil = ";
                                if (algo != null) {
                                    if (algo.equals("dt")) {
                                        output += dtm.executeInstanceWEKA(instance);
                                    } else if (algo.equals("nb")) {
                                        output += nbm.executeInstanceWEKA(instance);
                                    } else if (algo.equals("knn")) {
                                        output += knnm.executeInstanceWEKA(instance);
                                    }
                                }
                            }       
                        } else {
                            if(algo!=null){
                                if(algo.equals("dt")){
                                    dtm = new DecisionTree().DecisionTreeWEKA(dataset);
                                    output = dtm.crossv(5, dataset);
                                } else if(algo.equals("nb")){
                                    nbm = new NaiveBayesian().NaiveBayesWEKA(dataset);
                                    output = nbm.crossv(5, dataset);
                                } else if(algo.equals("knn")){
                                    knnm = new KNearestNeighbour().KNearestNeighbourWEKA(dataset);
                                    output = knnm.crossv(5, dataset);
                                }              
                            }                                    
                        }
                    } else if (software.equals("widi")){
                        if(input!=null){         
                            if (input.length() != 23) {
                                output = "invalid input";
                            } else {
                                instance = at.getInstance(input);
                                output = "hasil = ";
                                if(algo!=null){
                                    if(algo.equals("dt")){
                                        output += dtm.executeInstance(instance);
                                    } else if(algo.equals("nb")){
                                        output += nbm.executeInstance(instance);
                                    } else if(algo.equals("knn")){
                                        output += knnm.executeInstance(instance); 
                                    }
                                }
                            }       
                        } else {
                            if(algo!=null){
                                if(algo.equals("dt")){
                                    dtm = new DecisionTree().generateModel(dataset);
                                    output = dtm.crossval(5, dataset);
                                } else if(algo.equals("nb")){
                                    nbm = new NaiveBayesian().generateModel(dataset);
                                    output = nbm.crossval(5, dataset);
                                } else if(algo.equals("knn")){
                                    knnm = new KNearestNeighbour().generateModel(dataset,10);
                                    output = knnm.crossval(5, 10, dataset);
                                }                       
                            } 
                        }            
                    }
                }
           } else { 
           }
        %>        
        <div id="menu-wrapper">
            <div id="menu">
                <ul>
                    <li><a href="index.jsp">Preprocessing</a></li>
                    <li class="current_page_item"><a href="classification.jsp">Classification</a></li>
                </ul>
            </div>
            <!-- end #menu -->
        </div>
        <div id="header-wrapper">
            <div id="header">
                <div class ="logo">
                    <a><img src="Images/widi.png" alt="" /></a>
                </div>
            </div>
        </div>

        <div id="wrapper">
            <!-- end #header -->
            <div id="page">
                <div id="page-bgtop">
                    <div id="page-bgbtm">
                        <div id="content">
                            <h2>Output</h2>
                            <textarea rows="20" cols="70"> <%= output%> </textarea>
                            <div class ="button">
                                <button type="button">Calculate!</button>
                            </div>
                        </div>
                        <!-- end #content -->
                        <div id="sidebar">
                            <ul>
                                <li>
                                    <div class ="button">
                                        <form action="classification.jsp" enctype="multipart/form-data" method="get">
                                            <h3>Classifier</h3>                                            
                                            Algorithm</br>
                                        <input type="radio" name="algo" value="nb" witdh="5" <%=checkedNB%>>Naive Bayes</br>
                                            <input type="radio" name="algo" value="dt" witdh="5" <%=checkedDT%>>Decision Tree</br>
                                            <input type="radio" name="algo" value="knn" witdh="5" <%=checkedKNN%> >k=NN</br>
                                            Application</br>
                                            <input type="radio" name="software" value="weka" witdh="5" <%=checkedWEKA%>>Weka</br>
                                            <input type="radio" name="software" value="widi" witdh="5" <%=checkedWIDI%>>Widi's Heart</br>
                                            <input type="submit" name="button"></button>
                                        </form>                                                        
                                    </div>
                                    <div style="clear: both;">&nbsp;</div>
                                </li>
                                <li>
                                    <h2>Log</h2>
                                    <select width="50">
                                        <option>Volvo lwekjaflwjelfwjlfjew</option>
                                        <option>Saab</option>
                                        <option>Mercedes</option>
                                        <option>Audi</option>
                                    </select>
                                    <div style="clear: both;">&nbsp;</div>
                                </li>
                                <li>    
                                    <h2>Input</h2>
                                    <form action="classification.jsp" enctype="multipart/form-data" method="get">                                        
                                        <input type="text" name="input"></br>
                                        <input type="submit" name="button"></button>
                                    </form>      
                                </li>                                
                            </ul>
                        </div>
                        <!-- end #sidebar -->
                        <div style="clear: both;">&nbsp;</div>
                    </div>
                </div>
            </div>
            <!-- end #page -->
        </div>
        <div id="footer">
            <p>&copy; 2012 Sitename.com. | Photos by <a href="http://fotogrph.com/">Fotogrph</a> | Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
        </div>
        <!-- end #footer -->
    </body>
</html>

